package com.cr.business.controller;

import com.cr.business.domain.TbProducerInfo;
import com.cr.business.domain.dto.ProducerReqDto;
import com.cr.business.domain.vo.ProducerDataVo;
import com.cr.business.service.ITbProducerInfoService;
import com.cr.common.annotation.Log;
import com.cr.common.core.controller.BaseController;
import com.cr.common.core.domain.AjaxResult;
import com.cr.common.core.page.TableDataInfo;
import com.cr.common.enums.BusinessType;
import com.cr.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 生产人管理Controller
 * 
 * @author tang
 * @date 2025-08-19
 */
@RestController
@RequestMapping("/producer/info")
public class TbProducerInfoController extends BaseController
{
    @Resource
    private ITbProducerInfoService tbProducerInfoService;

    /**
     * 查询生产人信息列表
     */
    @PreAuthorize("@ss.hasPermi('producer:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProducerReqDto dto)
    {
        startPage();
        List<ProducerDataVo> list = tbProducerInfoService.selectTbProducerInfoList(dto);
        return getDataTable(list);
    }

    /**
     * 导出生产人信息列表
     */
    @PreAuthorize("@ss.hasPermi('producer:info:export')")
    @Log(title = "生产人管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProducerReqDto dto)
    {
        List<ProducerDataVo> list = tbProducerInfoService.selectTbProducerInfoList(dto);
        ExcelUtil<ProducerDataVo> util = new ExcelUtil<>(ProducerDataVo.class);
        util.exportExcel(response, list, "生产人信息数据");
    }

    /**
     * 修改生产人信息
     */
    @PreAuthorize("@ss.hasPermi('producer:info:edit')")
    @Log(title = "生产人管理", businessType = BusinessType.UPDATE)
    @PutMapping("updateProducerStatus")
    public AjaxResult updateProducerStatus(@RequestBody TbProducerInfo tbProducerInfo)
    {
        return toAjax(tbProducerInfoService.updateProducerStatus(tbProducerInfo));
    }

    /**
     * 删除生产人信息
     */
    @PreAuthorize("@ss.hasPermi('producer:info:remove')")
    @Log(title = "生产人管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{producerIds}")
    public AjaxResult remove(@PathVariable String[] producerIds)
    {
        return toAjax(tbProducerInfoService.deleteTbProducerInfoByProducerIds(producerIds));
    }
}
